package com.loong.musicdemo.ui.mine.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.loong.musicdemo.R;
import com.loong.musicdemo.model.Comment;
import com.loong.musicdemo.util.FormatTimeUtil;

import java.util.List;

public class MineCommentAdapter extends RecyclerView.Adapter<MineCommentAdapter.ViewHolder> {
    private List<Comment> commentList;
    private Context context;

    public MineCommentAdapter(List<Comment> commentList, Context context) {
        this.commentList = commentList;
        this.context = context;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.mv_comment_item,parent,false);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        Comment comment = commentList.get(position);
        Glide.with(context).load(comment.getUserAvatarUrl()).diskCacheStrategy(DiskCacheStrategy.NONE).skipMemoryCache(true).into(holder.commentator_img);
        holder.commentator_name.setText(comment.getUserNickName());
        holder.commentator_content.setText(comment.getContent());
        holder.commentator_like_count.setText(FormatTimeUtil.briefNumber(comment.getLikeCount()));
    }

    @Override
    public int getItemCount() {
        return commentList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        ImageView commentator_img;
        TextView commentator_name,commentator_content,commentator_like_count;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            commentator_img = itemView.findViewById(R.id.commentator_img);
            commentator_name = itemView.findViewById(R.id.commentator_name);
            commentator_content = itemView.findViewById(R.id.commentator_content);
            commentator_like_count = itemView.findViewById(R.id.commentator_like_count);
        }
    }
}
